package bishi.qunaerlvxing;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/09/14 19:06
 */
public class one {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String res;

        int _d_size = 0;
        _d_size = Integer.parseInt(in.nextLine().trim());
        int[] _d = new int[_d_size];
        int _d_item;
        for(int _d_i = 0; _d_i < _d_size; _d_i++) {
            _d_item = Integer.parseInt(in.nextLine().trim());
            _d[_d_i] = _d_item;
        }

        res = new one().solution(_d);
        System.out.println(res);
    }
    public String solution(int[] d) {
        int sum = Arrays.stream(d).sum();
        Arrays.sort(d);
        int p = sum%3;
        if (p!=0){
            for (int i=0;i<d.length;i++){
                if (d[i]%3==p) {
                    d[i] = -1;
                    p = 0;
                    break;
                }
            }
        }
        if (p!=0){
            for (int i=0;i<d.length;i++){
                if (d[i]%3==p) {
                    d[i] = -1;
                    p--;
                    if (p==0){
                        break;
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        if (p==0){
            for (int i=d.length-1;i>=0;i--){
                if (d[i]==-1) continue;
                sb.append(d[i]);
            }
        }
        return sb.toString();
    }
}
